
#include "mypushbtn.h"
#include <QPixmap>
#include <QDebug>
#include <QPropertyAnimation>
mypushbtn::mypushbtn(QWidget *parent)
    : QPushButton{parent}
{

}

mypushbtn::mypushbtn(QString norimg, QString primg)
{
    this->norimgpath = norimg;
    this->primgpath = primg;

    QPixmap pix;
    if (!pix.load(norimg))
    {
        qDebug()<<"图片加载失败";
        return;
    }
    //this->setFixedSize(pix.width(), pix.height());

    this->setStyleSheet("QPushButton{border:0px}");

    this->setIcon(pix);

    this->setFixedSize(70, 70);

    this->setIconSize(QSize(70, 70));


}

void mypushbtn::zoomup()//向上跳
{
    QPropertyAnimation * ani = new QPropertyAnimation(this, "geometry");

    //时间间隔
    ani->setDuration(200);

    //起始位置
    ani->setStartValue(QRect(this->x(), this->y(), this->width(), this->height()));
    //结束位置
    ani->setEndValue(QRect(this->x(), this->y()+15, this->width(), this->height()));

    //设置弹跳曲线
    ani->setEasingCurve(QEasingCurve::OutBounce);

    //执行动画
    ani->start();
}

void mypushbtn::zoomdown()//向下跳
{
    QPropertyAnimation * ani = new QPropertyAnimation(this, "geometry");

    //时间间隔
    ani->setDuration(200);

    //起始位置
    ani->setStartValue(QRect(this->x(), this->y()+15, this->width(), this->height()));
    //结束位置
    ani->setEndValue(QRect(this->x(), this->y(), this->width(), this->height()));

    //设置弹跳曲线
    ani->setEasingCurve(QEasingCurve::OutBounce);

    //执行动画
    ani->start();
}
